home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5371 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  159 lines

  1. Path: datatamers.com!wnc
  2. From: wnc@datatamers.com ()
  3. Newsgroups: comp.lang.c
  4. Subject: newbie's problems w/ linux
  5. Date: 12 Feb 1996 17:02:00 GMT
  6. Organization: DATATAMERS
  7. Message-ID: <4fnrq8$53v@news.datatamers.com>
  8. NNTP-Posting-Host: dt1.datatamers.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. i'm currently taking a beginners C class, and i was attempting to make a 
  12. program which figures out GPA for my classes. I'm running windows 95, and 
  13. when i compile it for DOS, it runs fine, but, when i compile it for 
  14. linux, using gcc, i keep getting this same error, basically what happens 
  15. is that after taking input through scanf(), it will skip the next 
  16. scanf(), even though i'm using fflush(). here is a sample output of what 
  17. happens.
  18.  
  19.  
  20. GPA version .9beta, written by wnc@datatamers.com
  21.  
  22.  
  23. How many classes do you have? 2
  24. What grade did you get in period 1? a
  25. What grade did you get in period 2? Do you have any AP classes?
  26.  
  27. Your Total GPA for 2 period(s) is 0!
  28. Which is equivilent to a(n) F
  29.  
  30.  
  31. here is the source, if you can figure out what's wrong w/ it, please 
  32. mail me at wnc@datatamers.com, thanks in advance.
  33.  
  34. #include <stdio.h>
  35. void convert(void);
  36. void endo(void);
  37. float converted, gpa = 0., ap, donegpa;
  38. int periods;
  39. char grade, endofit[2], yesno;
  40. void main()
  41. {
  42. short int counter, counter2;
  43. printf("\n\n\n\n\n\n\nGPA version .9beta, written by wnc@datatamers.com\n\n\n"); 
  44. printf("How many classes do you have? ");
  45. scanf("%i", &periods);
  46. fflush(stdin);
  47. for ( counter = 1; counter <= periods; ++counter )
  48. {
  49. printf("What grade did you get in period %i? ", counter);
  50. scanf("%d", &grade);
  51. fflush(stdin);
  52. convert();
  53. gpa += converted;
  54. }
  55. printf("Do you have any AP classes? ");
  56. scanf("%d",& yesno);
  57. fflush(stdin);
  58. if (yesno=='y' || yesno=='Y')
  59. {
  60. printf("How many of them are AP? ");
  61. scanf("%f", &ap);
  62. gpa += ap;
  63. }
  64. donegpa= gpa / periods;
  65. endo();
  66. printf("\n\nYour Total GPA for %i period(s) is %.3g!\nWhich is equivilent to a(n) ", periods, donegpa);
  67. printf("%c%c\n\n\n", endofit[1], endofit[2]);
  68. }
  69. void convert(void)
  70. {
  71.     switch (grade)
  72. {
  73.     case 'a':
  74.     case 'A':
  75.         converted =4.;
  76.         break;
  77.     case 'b':
  78.     case 'B':
  79.         converted =3.;
  80.         break;
  81.     case 'c':
  82.     case 'C':
  83.         converted =2.;
  84.         break;
  85.     case 'd':
  86.     case 'D':
  87.         converted =1.;
  88.         break;
  89.     default:
  90.         converted =0.;
  91.         break;
  92. }
  93. }
  94. void endo(void)
  95. {
  96. if (donegpa>=4.0)
  97. {
  98. endofit[1] = 'A';
  99. endofit[2] = ' ';
  100. }
  101. else if (donegpa>=3.5)
  102. {
  103. endofit[1] = 'A';
  104. endofit[2] = '-';
  105. }
  106. else if (donegpa>3.0)
  107. {
  108. endofit[1] = 'B';
  109. endofit[2] = '+';
  110. }
  111. else if (donegpa==3.0)
  112. {
  113. endofit[1] = 'B';
  114. endofit[2] = ' ';
  115. }
  116. else if (donegpa>=2.5)
  117. {
  118. endofit[1] = 'B';
  119. endofit[2] = '-';
  120. }
  121. else if (donegpa>2.0)
  122. {
  123. endofit[1] = 'C';
  124. endofit[2] = '+';
  125. }
  126. else if (donegpa==2.0)
  127. {
  128. endofit[1] = 'C';
  129. endofit[2] = ' ';
  130. }
  131. else if (donegpa>=1.5)
  132. {
  133. endofit[1] = 'C';
  134. endofit[2] = '-';
  135. }
  136. else if (donegpa>1.0)
  137. {
  138. endofit[1] = 'D';
  139. endofit[2] = '+';
  140. }
  141. else if (donegpa==1.0)
  142. {
  143. endofit[1] = 'D';
  144. endofit[2] = ' ';
  145. }
  146. else if (donegpa>=.5)
  147. {
  148. endofit[1] = 'D';
  149. endofit[2] = '-';
  150. }
  151. else
  152. {
  153. endofit[1] = 'F';
  154. endofit[2] = ' ';
  155. }
  156. }
  157.  
  158.  
  159.